banner

SNAP - 07 (Introduction to Variables Part 2)

OPENING QUESTIONS: Can you suggest an instance when it might not be wise to have a variable that is available to ALL parts of your program?

OBJECTIVES:

    • I will be able to explain the difference between system variables, global variables and script variables after today's class

WORD FOR TODAY:

  • system variable (a data bucket provided by SNAP)
  • variable (a user-defined data bucket)
  • global variable (available EVERYWHERE)
  • script variable (PRIVATE)

TIPS O' THE DAY

1) ALWAYS have a 'clear' button ( ) on hand... it makes clearing the screen much easier than having to hunt for it.

2) You can also 'delete' a script by dragging it off the scripting area

3) If you know the name of a block but can't remember where it is, use the ALWAYS helpful ctrl-F key (that works on web sites AND pdf documents by the way)

4) How can you *duplicate* a script or part of a script (this will be VERY helpful in today's lab)

5) Always a good idea to have an x 'go to 0' and a y 'go to 0' to re-center your sprite if it get's lost

6) Right Mouse click on the stage and select 'show all' to bring sprite(s) back

WORK O' THE DAY:

Very quickly -- please write down a list of our "BEST PRACTICES"

Compare your list to your group... do they match?

Any questions, comments or concerns about our list so far? (Some of which we haven't put into practice, oddly enough)

═══════════════════════════

Open snap and create a new script

  • Work with your group to determine how to duplicate the existing sprite on the stage

  • Now make two copies of your existing sprite so that you have a total of two of them

═══════════════════════════

Now please return to your first sprite and:

  • Write a short script that ASKS your user to input their first name.

  • Write a short script associated with your second sprite that says "User Name = " for 2 seconds (be sure and use the operator along with the system variable to display the input value)

  • Write a short script associated with your third sprite that says "be sure and use the dddoperator along with the ssssystem variable to display the input value")

Notice that the system variable sss is available to each sprite.

Now please create a variable called "NAME" and change your code in the first script so that the user input is stored in the "NAME" variable.

Notice that the NAME variable is ALSO available to sprites 2 and 3... (How can you tell?)

═══════════════════════════

The answer system variable is available to all parts of all scripts of your program at all times. That can be really helpful at times....

Please have a conversation with your group to outline why it can be VERY helpful to have information available GLOBALLY... in other words, every program in every sprite can see, access and change the data in a global variable.

═══════════════════════════

Now please go to your second variable and take a look at the code there.

This time, I'm going to have you create a similar script that asks the user for their age and save that information to a SCRIPT VARIABLE named "Local Name".

Open your 3rd sprite and notice that the "Local Name" script variable that you created in your 2nd sprite is not avaialble... why might that be an advantage?

═══════════════════════════